/*
 * TcpSocket.h
 *
 *  Created on: Nov 9, 2012
 *      Author: root
 */

#ifndef zeus_TCPSOCKET_H_
#define zeus_TCPSOCKET_H_

#include "base/Types.h"
#include "SocketService.h"
#include "Buffer.h"
#include "Error.h"

namespace zeus
{

class TcpSocket:private NonCopyAble
{
public:

	typedef std::function<void (const Error & err,size_t bytes_transferred)> IoHandler;

private:
	SocketService _service;

	int32 _fd;

	sockaddr_in _peer;

public:
	explicit TcpSocket(IoService & io_service);
	virtual ~TcpSocket();

public:

	int32 get_fd()const;

	void set_fd(int32 fd);

	void set_peer(const sockaddr_in & peer);

private:

	void enable_writing();

	void enable_reading();

public:

	void read_solid(Buffer & buff,size_t size,const IoHandler & complete_handler);

	void write_solid(Buffer & buff,size_t size,const IoHandler & complete_handler);

	void close();

};

} /* namespace zeus */
#endif /* zeus_TCPSOCKET_H_ */
